//
//  MyLoanAttestDetailViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/20.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "MyLoanAttestDetailViewController.h"

@interface MyLoanAttestDetailViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UILabel *companyName;
@property (weak, nonatomic) IBOutlet UILabel *mainBusiness;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property(nonatomic,strong)NSString * phoneNum;

@property (weak, nonatomic) IBOutlet UILabel *attestName;
@property (weak, nonatomic) IBOutlet UILabel *attesMoney;
@property (weak, nonatomic) IBOutlet UILabel *attestTime;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UITextView *attestTextView;

@end

@implementation MyLoanAttestDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    [self getAttestDetail];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.scroView];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 545), NO);
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark === 电话
- (IBAction)call:(id)sender {
    [Common callPhone:_phoneNum view:self.view];
}


#pragma mark === 获取申请贷款详情
- (void)getAttestDetail{
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    
    [dic setObject:_loanId forKey:@"fappId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryMyApplyForLoanDetail withHttpType:@"POST" withTag:GS_GS_queryMyApplyForLoanDetail];

}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==GS_GS_queryMyApplyForLoanDetail) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSDictionary * dic = database[@"result"][@"apply"];
            NSDictionary * companyDic = dic[@"finacialCompany"];
            NSDictionary * attestDic = dic[@"memberUser"];
            
            _companyName.text = [NSString stringWithFormat:@"%@",companyDic[@"fcomName"]];
            _mainBusiness.text = [NSString stringWithFormat:@"%@",companyDic[@"fcomMainBusi"]];
            _dateLabel.text = [NSString stringWithFormat:@"%@",dic[@"fappAcceptTime"]];
            _addressLabel.text = [NSString stringWithFormat:@"%@",companyDic[@"fcomAddress"]];
            _phoneNum = [NSString stringWithFormat:@"%@",companyDic[@"fcomPhone"]];
            
            _attestName.text = [NSString stringWithFormat:@"%@",attestDic[@"museUserName"]];
            _attesMoney.text = [NSString stringWithFormat:@"￥%.2f",[dic[@"fappPrice"] floatValue]];
            _attestTime.text = [NSString stringWithFormat:@"%@",dic[@"fappCreateTime"]];
            
            NSString * status = [NSString stringWithFormat:@"%@",dic[@"fappLoanStatus"]];
            if ([status isEqualToString:@"1"]) {
                status = @"已预申请";
            }else if ([status isEqualToString:@"2"]) {
                status = @"已正式申请(待受理)";
            }else if ([status isEqualToString:@"3"]) {
                status = @"已受理";
            }else if ([status isEqualToString:@"4"]) {
                status = @"已放款";
            }
            _statusLabel.text = status;
            
            _attestTextView.text = [NSString stringWithFormat:@"%@",dic[@"fappContent"]];
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    }


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
